package shapes.shapes2D.distribution.random 
{
	
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class PRNG
	{
		static private var _seed:Number;
		static private var x:Number;
		static private var a:Number;

		static public function get seed():uint { return _seed; }
		
		static public function set seed(value:uint):void 
		{
			if ( value <= 0xFF ) value = 0xFF;
			if ( value >= 0xFFFFFFFF ) value = 0xFFFFFFFe;
			
			
			_seed = value;
			
			x = seed / 0xFFFFFFFF;
			
			a = ( x / 2 ) ^ x / 2;
			
		}
		
		static public function random():Number
		{
			
			if ( isNaN( _seed ) ) seed = 0xFF;
			
			a += x;
			x = a * x + a;
			x -= int( x );
			return x;
			
		}
		
	}

}